/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Mansur
 */
@Entity
@Table(name = "ship_visitfl")
@NamedQueries({
    @NamedQuery(name = "ShipVisitFlow.findAll", query = "SELECT s FROM ShipVisitFlow s"),
    @NamedQuery(name = "ShipVisitFlow.listApproved", query = "SELECT s FROM ShipVisitFlow s WHERE s.status = 'A' ORDER BY s.infoAudit.createDate "),
    @NamedQuery(name = "ShipVisitFlow.listRejected", query = "SELECT s FROM ShipVisitFlow s WHERE s.status = 'R' ORDER BY s.infoAudit.createDate "),
    @NamedQuery(name = "ShipVisitFlow.listKIV", query = "SELECT s FROM ShipVisitFlow s WHERE s.status = 'K' ORDER BY s.infoAudit.createDate ")})
//@NamedQueries({
//    @NamedQuery(name = "ShipVisitFlow.findAll", query = "SELECT s FROM ShipVisitFlow s")})
public class ShipVisitFlow implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ship_visitfl_id")
    private Integer shipVisitFlowId;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;
    
    @Column(name = "department_crn")
    private String currentDepartment;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "vessel_id")
    private Vessel vessel;
    
    @Column(name = "date_visit")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateVisit;
    
    @Column(name = "location")
    private String location;
    
    @Column(name = "description")
    private String description;
    
    @Column(name = "delete_flag")
    private String deleted;
    
    @Column(name = "status_flag")
    private String status;  // K=KIV, A=Approved, R=Rejected
    
    @Column(name = "reject_note")
    private String rejectNote;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "verifier_id")
    private User verifierId;
    
    @Column(name = "imo_number")
    private String imoNumber;
    
    @Column(name = "gross_ton")
    private String grossTonnage;
    
    @Column(name = "master_name")
    private String masterName;
    
    @Column(name = "summary")
    private String summary;
    
    @Column(name = "purpose")
    private String purpose;
    
    @Column(name = "general_cond")
    private String generalCondition;
    
    @Column(name = "accomodation")
    private String accomodation;
    
    @Column(name = "deck")
    private String deck;
    
    @Column(name = "engine")
    private String engine;
    
    @Column(name = "crew_morale")
    private String crewMorale;
    
    @Column(name = "food_meal")
    private String foodMeal;
    
    @Column(name = "other")
    private String other;
    
    @Column(name = "conclusion")
    private String conclusion;
    
    @Column(name = "recommend")
    private String recommend;
    
    @Embedded
    private InfoAudit infoAudit;
    
    @OneToMany (mappedBy = "shipVisitFlow" , fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ShipVisitFlowFile> flowFileList;
    
    public ShipVisitFlow() {
    }

    public Integer getShipVisitFlowId() {
        return shipVisitFlowId;
    }

    public void setShipVisitFlowId(Integer shipVisitFlowId) {
        this.shipVisitFlowId = shipVisitFlowId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getCurrentDepartment() {
        return currentDepartment;
    }

    public void setCurrentDepartment(String currentDepartment) {
        this.currentDepartment = currentDepartment;
    }

    public Vessel getVessel() {
        return vessel;
    }

    public void setVessel(Vessel vessel) {
        this.vessel = vessel;
    }

    public Date getDateVisit() {
        return dateVisit;
    }

    public void setDateVisit(Date dateVisit) {
        this.dateVisit = dateVisit;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDeleted() {
        return deleted;
    }

    public void setDeleted(String deleted) {
        this.deleted = deleted;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getRejectNote() {
        return rejectNote;
    }

    public void setRejectNote(String rejectNote) {
        this.rejectNote = rejectNote;
    }

    public User getVerifierId() {
        return verifierId;
    }

    public void setVerifierId(User verifierId) {
        this.verifierId = verifierId;
    }

    public String getImoNumber() {
        return imoNumber;
    }

    public void setImoNumber(String imoNumber) {
        this.imoNumber = imoNumber;
    }

    public String getGrossTonnage() {
        return grossTonnage;
    }

    public void setGrossTonnage(String grossTonnage) {
        this.grossTonnage = grossTonnage;
    }

    public String getMasterName() {
        return masterName;
    }

    public void setMasterName(String masterName) {
        this.masterName = masterName;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getPurpose() {
        return purpose;
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    public String getGeneralCondition() {
        return generalCondition;
    }

    public void setGeneralCondition(String generalCondition) {
        this.generalCondition = generalCondition;
    }

    public String getAccomodation() {
        return accomodation;
    }

    public void setAccomodation(String accomodation) {
        this.accomodation = accomodation;
    }

    public String getDeck() {
        return deck;
    }

    public void setDeck(String deck) {
        this.deck = deck;
    }

    public String getEngine() {
        return engine;
    }

    public void setEngine(String engine) {
        this.engine = engine;
    }

    public String getCrewMorale() {
        return crewMorale;
    }

    public void setCrewMorale(String crewMorale) {
        this.crewMorale = crewMorale;
    }

    public String getFoodMeal() {
        return foodMeal;
    }

    public void setFoodMeal(String foodMeal) {
        this.foodMeal = foodMeal;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }

    public String getConclusion() {
        return conclusion;
    }

    public void setConclusion(String conclusion) {
        this.conclusion = conclusion;
    }

    public String getRecommend() {
        return recommend;
    }

    public void setRecommend(String recommend) {
        this.recommend = recommend;
    }

    public InfoAudit getInfoAudit() {
        return infoAudit;
    }

    public void setInfoAudit(InfoAudit infoAudit) {
        this.infoAudit = infoAudit;
    }

    public List<ShipVisitFlowFile> getFlowFileList() {
        return flowFileList;
    }

    public void setFlowFileList(List<ShipVisitFlowFile> flowFileList) {
        this.flowFileList = flowFileList;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (shipVisitFlowId != null ? shipVisitFlowId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ShipVisitFlow)) {
            return false;
        }
        ShipVisitFlow other = (ShipVisitFlow) object;
        if ((this.shipVisitFlowId == null && other.shipVisitFlowId != null) || (this.shipVisitFlowId != null && !this.shipVisitFlowId.equals(other.shipVisitFlowId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "exatrez.model.ShipVisitFlow[ shipVisitFlowId=" + shipVisitFlowId + " ]";
    }
    
    public List<ShipVisitFlowFile> getListFilteredFile(){
        List<ShipVisitFlowFile> l = new ArrayList<ShipVisitFlowFile>();
        for (ShipVisitFlowFile svf : flowFileList) {
            if(svf.getDeleted().equals("N")){
                l.add(svf);
            }
        }
        return l;
    }
}
